$(function () {
    Time()
    WuLiaoGongXu()
})

function fh() {
    location.href = "../../li_meng/WuLiaoSheJiDan.html";
}

function Time() {
    var time = new Date();
    var y = time.getFullYear();
    var mon = time.getMonth() + 1; //0-11
    var d = time.getDate();
    var h = time.getHours();
    var m = time.getMinutes();
    var s = time.getSeconds();
    $("#date").val(y + "-" + mon + "-" + d + " " + h + ":" + m + ":" + s);
}

let list = [];

function WuLiaoGongXu() {
    let user = JSON.parse(localStorage.getItem("user"));
    $("#rname").val(user.rname);
    let WuLiaoMde = JSON.parse(localStorage.getItem("WuLiaoMde"));
    //工序设计单编号
    $("#designid").text(WuLiaoMde.designid);

    //工序名称
    let mDesignProcedureDetails = JSON.parse(localStorage.getItem("MDesignProcedureDetails"));
    $("#procedurename").text(mDesignProcedureDetails.procedurename)

    let shu = JSON.parse(localStorage.getItem("shuliangList"));
    $.ajax({
        type: "post",
        url: "/Dmoduledetails.do/ChaWuLiao",
        data: {productid: WuLiaoMde.productid},
        success: function (data) {
            list = data;
            let tr = "<tr>\n" +
                "       <th>序号</th>\n" +
                "       <th>物料名称</th>\n" +
                "       <th>物料编号</th>\n" +
                "       <th>描述</th>\n" +
                "       <th>本工序数量</th>\n" +
                "       <th>单位</th>\n" +
                "       <th>单价（元）</th>\n" +
                "       <th>小计(元)</th>\n" +
                "       </tr>";
            for (let i = 0; i < data.length; i++) {
                tr += "<tr>\n" +
                    "       <td>" + data[i].id + "</td>\n" +
                    "       <td>" + data[i].productname + "</td>\n" +
                    "       <td>" + data[i].productid + "</td>\n" +
                    "       <td>" + data[i].productdescribe + "</td>\n" +
                    "       <td>" + shu[i] + "</td>\n" +
                    "       <td>" + data[i].amountunit + "</td>\n" +
                    "       <td>" + data[i].costprice + "</td>\n" +
                    "       <td><span class='xiaojiao'>" + (data[i].costprice * shu[i]) + "</span></td>\n" +
                    "       </tr>"
            }
            $("#tableAdd").html(tr)
        }
    })
}

function TiJiao() {
    let MDesignProcedureDetails = localStorage.getItem("MDesignProcedureDetails");
    let shu = localStorage.getItem("shuliangList");
    let DModuleDetails = JSON.stringify(list);

    $.post("/Mdesignprocedure.do/LiMengMdesignprocedure", {
            MDesignProcedureDetails: MDesignProcedureDetails,
            shu: shu, DModuleDetails: DModuleDetails
        },
        function (sdate) {
            localStorage.removeItem("shuliangList");
            location.href = "../../li_meng/GXWuLiaoSheJi(2).html";
        })
}
